#!usr/bin/env python
# -*- coding:utf-8 _*-
"""
@author:chengyanan
@file: find_element.py
@time: 2019/12/18  10:52 下午
"""
import os
import sys

path = os.path.dirname(os.getcwd())
sys.path.append(path)
from util.red_ini import ReadIni
from log.user_log import UserLog


class FindElement:
    def __init__(self, driver):
        get_user_log = UserLog()
        self.logger = get_user_log.get_log()
        self.driver = driver
    def get_element(self, key):
        read_init = ReadIni()
        data = read_init.get_value(key)  # id>register_email
        by = data.split('>')[0]  # by=id
        value = data.split(">")[1]  # value=  register_nickname
        self.logger.info("定位方式:" + by + "--->定位值:" + value)

        try:
            if by == 'id':
                print('Value', value)
                return self.driver.find_element_by_id(value)
            elif by == 'name':
                return self.driver.find_element_by_name(value)
            elif by == 'className':
                return self.driver.find_element_by_class_name(value)
            elif by == 'link':
                return self.driver.find_element_by_partial_link_text(value)
            elif by == "xpath":
                return self.driver.find_element_by_xpath(value)
            else:
                print("定位方式输入错误")
        except:
            return None
